<?php
@session_start();
class User extends WebBase{
	public $title='\x51\x51\x34\x31\x30\x37\x34\x39\x39\x38\x35';
	private $vcodeSessionName='blast_vcode_session_name';
	
	/**
	 * 用户登录页面
	 */
	public final function login(){
		$this->display('user/login.php');
	}

        /**
         * 用户登录页面
         */
        public final function login_t(){
            $this->display('user/login_t.php');
        }
		
	public final function logininfo(){
		$this->display('user/logininfo.php');
	}

	/**
	 * 用户登出操作
	 */
	public final function logout(){
		$_SESSION=array();
		if($this->user['uid']){
			$this->update("update {$this->prename}member_session set isOnLine=0 where uid={$this->user['uid']}");
			echo "<script>alert('您已安全退出，欢迎再次光临!');window.location.href='/index.php'</script>";
	        exit();
		}
	}
	//设置称昵	
	public final function nickname(){
		$this->display('user/nickname.php');
	}
	public final function bulletin(){
		$this->display('user/bulletin.php');
	}
	
	private function getBrowser(){
		$flag=$_SERVER['HTTP_USER_AGENT'];
		$para=array();
		
		// 检查操作系统
		if(preg_match('/Windows[\d\. \w]*/',$flag, $match)) $para['os']=$match[0];
		
		if(preg_match('/Chrome\/[\d\.\w]*/',$flag, $match)){
			// 检查Chrome
			$para['browser']=$match[0];
		}elseif(preg_match('/Safari\/[\d\.\w]*/',$flag, $match)){
			// 检查Safari
			$para['browser']=$match[0];
		}elseif(preg_match('/MSIE [\d\.\w]*/',$flag, $match)){
			// IE
			$para['browser']=$match[0];
		}elseif(preg_match('/Opera\/[\d\.\w]*/',$flag, $match)){
			// opera
			$para['browser']=$match[0];
		}elseif(preg_match('/Firefox\/[\d\.\w]*/',$flag, $match)){
			// Firefox
			$para['browser']=$match[0];
		}elseif(preg_match('/OmniWeb\/(v*)([^\s|;]+)/i',$flag, $match)){
			//OmniWeb
			$para['browser']=$match[2];
		}elseif(preg_match('/Netscape([\d]*)\/([^\s]+)/i',$flag, $match)){
			//Netscape
			$para['browser']=$match[2];
		}elseif(preg_match('/Lynx\/([^\s]+)/i',$flag, $match)){
			//Lynx
			$para['browser']=$match[1];
		}elseif(preg_match('/360SE/i',$flag, $match)){
			//360SE
			$para['browser']='360安全浏览器';
		}elseif(preg_match('/SE 2.x/i',$flag, $match)) {
			//搜狗
			$para['browser']='搜狗浏览器';
		}else{
			$para['browser']='unkown';
		}
		//print_r($para);exit;
		return $para;
	}

	/*活动*/
	public final function huodong(){
		$this->display('notice/huodong.php');
	}
	/*登录前活动*/
	public final function loginhuodong(){
		$this->display('notice/loginhuodong.php');
	}
	
	/**
	 * 用户登录检查
	 */
	public final function logined(){
		$username=wjStrFilter($_POST['username']);
		$password=wjStrFilter($_POST['password']);
		$vcode=$_POST['vcode'];
        if(!ctype_alnum($username)) throw new Exception('用户名包含非法字符,请重新输入');

		if(!isset($username)){
			throw new Exception('请输入用户名');
		}
		if(!$password){
			throw new Exception('不允许空密码登录');
		}
		
		
		if(!$vcode){
			throw new Exception('请输入验证码');
		}
		$sql="select * from {$this->prename}members where isDelete=0 and admin=0 and username=?";
		if(!$user=$this->getRow($sql, $username)){
			throw new Exception('用户名或密码不正确');
		}
		if(md5($password)!=$user['password']){
			throw new Exception('密码不正确');
		}
		if($vcode!=$_SESSION[$this->vcodeSessionName]){
			throw new Exception('验证码错误，请重新输入');
		}
		if(!$user['enable']){
			throw new Exception('您的帐号被冻结，请联系管理员。');
		}
		$session=array(
			'uid'=>$user['uid'],
			'username'=>$user['username'],
			'session_key'=>session_id(),
			'loginTime'=>$this->time,
			'accessTime'=>$this->time,
			'loginIP'=>self::ip(true)
		);
		
		$session=array_merge($session, $this->getBrowser());
		
		if($this->insertRow($this->prename.'member_session', $session)){
			$user['sessionId']=$this->lastInsertId();
		}
		$_SESSION[$this->memberSessionName]=serialize($user);

		// 把别人踢下线
		$this->update("update {$this->prename}member_session set isOnLine=0,state=1 where uid={$user['uid']} and id<{$user['sessionId']}");

		return $user;
	}


	/**
	 * 用户登录检查2
	 */
	public final function ajaxlogined(){
		$username=wjStrFilter($_POST['username']);
		$password=wjStrFilter($_POST['password']);
		$vcode=$_POST['vcode'];
        if(!ctype_alnum($username)) {
        	return array('msg'=>'用户名包含非法字符,请重新输入','code'=>1);
        }
		if(!isset($username)){
			return array('msg'=>'请输入用户名','code'=>1);
		}
		if(!$password){
			return array('msg'=>'不允许空密码登录','code'=>1);
		}
		if(!$vcode){
		return	array('msg'=>'请输入验证码','code'=>1);
		}
		$sql="select * from {$this->prename}members where isDelete=0 and admin=0 and username=?";
		if(!$user=$this->getRow($sql, $username)){
		return	array('msg'=>'用户名不存在','code'=>1);
		}
		if(md5($password)!=$user['password']){
		return	array('msg'=>'密码不正确','code'=>1);
		}
		if($vcode!=$_SESSION[$this->vcodeSessionName]){
		return	array('msg'=>'验证码错误，请重新输入','code'=>1);
		}
		if(!$user['enable']){
		return	array('msg'=>'您的帐号被冻结，请联系管理员。','code'=>1);
        }
		$session=array(
			'uid'=>$user['uid'],
			'username'=>$user['username'],
			'session_key'=>session_id(),
			'loginTime'=>$this->time,
			'accessTime'=>$this->time,
			'loginIP'=>self::ip(true)
		);
		
		$session=array_merge($session, $this->getBrowser());
		
		if($this->insertRow($this->prename.'member_session', $session)){
			$user['sessionId']=$this->lastInsertId();
		}
		$_SESSION[$this->memberSessionName]=serialize($user);

		// var_dump($user);
		// echo "update {$this->prename}member_session set isOnLine=0,state=1 where uid={$user['uid']} and id<{$user['sessionId']}";
		// 把别人踢下线
		$this->update("update {$this->prename}member_session set isOnLine=0,state=1 where uid={$user['uid']} and id<{$user['sessionId']}");

		$sql="select count(id) from {$this->prename}message_receiver where to_uid=? and is_readed=0 and is_deleted=0";
		$num=$this->getValue($sql,$user['uid']);
		$user['msgcount'] = $num;
		// var_dump($user);
		// opJson('您的帐号被冻结，请联系管理员。',1,null);
		return array('msg'=>'success','code'=>0,'data'=>$user);
		
	}


	//输出json格式数据
	// public final function opJson($msg,$code,$data=null){
	// 	$info['msg'] = $msg;
	// 	$info['code'] = $code;
	// 	$info['data'] = $data;
	// 	echo json_encode($info);
	// 	die();
	// }

	/**
	 * 验证码产生器
	 */
	public final function vcode($rmt=null){
		$lib_path=$_SERVER['DOCUMENT_ROOT'].'/xingcai_lib/';
		include_once $lib_path .'classes/CImage.class';
		$width=72;
		$height=24;
		$img=new CImage($width, $height);
		$img->sessionName=$this->vcodeSessionName;
		$img->printimg('png');
	}

	public final function inAgent(){
		if(!$_POST)  throw new Exception('提交数据出错，请重新操作');
		$para['name']=wjStrFilter($_POST['content1']);
		$para['amount']=wjStrFilter($_POST['content2']);
		$para['qq']=wjStrFilter($_POST['content3']);

		if(!ctype_digit($para['amount'])) throw new Exception('销量包含非法字符，请填入纯数字');
		if(!ctype_digit($para['qq'])) throw new Exception('QQ号码包含非法字符');
		if(strlen($para['name'])>40) throw new Exception('平台名请不要超过40个字符');

		$para['time']=$this->time;
		$para['ip']=$this->ip(true);
		if(!$this->insertRow($this->prename .'inagent', $para)) throw new Exception('提交出错，请重试!');

		return '申请信息已成功提交';
	}
	
	/**
	 * 推广注册
	 */
	public final function r($userxxx){
		if(!$userxxx){
			$this->display('team/register.php');
		}else{
			$lid = $this->myxor($this->hexToStr($userxxx));
			if(!is_numeric($lid)){
				$this->display('team/register.php');
			}else{
				if(!$link=$this->getRow("select * from {$this->prename}links where lid=?",$lid)){
					$this->display('team/register.php');
				}else{
					if(!$link['enable']){
						$this->display('team/register.php');
					}else{
						$this->display('team/register.php',0,$userxxx);
					}
				}
			}
		}
	}
    public final function reg(){
		if(!$_POST)  throw new Exception('注册失败，请重新操作');

		$user=wjStrFilter($_POST['username']);
		$password=$_POST['password'];
		$qq=wjStrFilter($_POST['qq']);
		$vcode=wjStrFilter($_POST['vcode']);
		$codec=wjStrFilter($_POST['codec']);
   
		
		if(strlen($user)<5 || strlen($user)>15) throw new Exception('帐号为5-15位,请重新输入');
		if(!ctype_alnum($user)) throw new Exception('帐号包含非法字符');
		if(strlen($password)<6) throw new Exception('密码至少6位');
		if(strlen($qq)<6 || strlen($qq)>11) throw new Exception('QQ号为6-11位,请重新输入');
		if(!ctype_digit($qq)) throw new Exception('QQ包含非法字符');
		
		if(strtolower($vcode)!=$_SESSION[$this->vcodeSessionName]){
			throw new Exception('验证码不正确。');
		}
		
		//验证码使用完之后要清空
		unset($_SESSION[$this->vcodeSessionName]);
		
		if(!$codec) throw new Exception('链接错误');
		$lid = $this->myxor($this->hexToStr($codec));
		$zczs=$this->getValue("select Value from {$this->prename}params where name='zczs'");
		if(!$link=$this->getRow("select * from {$this->prename}links where lid=?",$lid)){
			throw new Exception('该链接已失效，请联系您的上级重新索取注册链接！！');
		}else{
			$para=array(
					'username'=>$user,
					'type'=>$link['type'],
					'password'=>md5($password),
				    'source'=>3,
					'parentId'=>$link['uid'],
					'parents'=>$this->getValue("select parents from {$this->prename}members where uid=?",$link['uid']),
					'fanDian'=>$link['fanDian'],
					'regIP'=>$this->ip(true),
					'regTime'=>$this->time,
					'qq'=>$qq,
					'coin'=>0,
					'fcoin'=>0,
					'score'=>0,
					'scoreTotal'=>0,
					'admin'=>0				
			);
			
			if(!$para['nickname']) $para['nickname']=$para['username'];
			if(!$para['name']) $para['name']=$para['username'];
			
			try{
				$this->beginTransaction();
				$sql="select username from {$this->prename}members where username=?";
			    if($this->getValue($sql, $para['username'])) throw new Exception('用户"'.$para['username'].'"已经存在');
			    if($this->insertRow($this->prename .'members', $para)){
				$id=$this->lastInsertId();
				$sql="update {$this->prename}members set parents=concat(parents, ',', $id) where `uid`=$id";
				$this->update($sql);
                
				//注册活动
				if($para['parentId'] && $this->settings['regReceiveMoney'] && $this->settings['maxRegCount']){
					$regCount=$this->getValue("select count(*) from {$this->prename}members where parentId={$para['parentId']} and regIP={$this->ip(true)}");
					$maxRegCount=intval($this->settings['maxRegCount']);
					$amount=floatval($this->settings['regReceiveMoney']);
						if($regCount<=$maxRegCount){
							$this->addCoin(array(
								'uid'=>$para['parentId'],
								'liqType'=>55,
								'info'=>'注册佣金',
								'coin'=>$amount,
								'extfield0'=>$id,
								'extfield1'=>''
							));	
							
						}
				}///注册活动 end

				$this->commit();
				return '注册成功';
			}else{
				throw new Exception('注册失败');
			}	
			}catch(Exception $e){
				$this->rollBack();
				throw $e;
			}
		}
	}
	
	/**
	 * 推广注册2
	 */
	public final function _api($userxxx){
		if(!$userxxx){
			$this->display('team/regoster.php');
		}else{
			$lid = $this->myxor($this->hexToStr($userxxx));
			if(!is_numeric($lid)){
				$this->display('team/regoster.php');
			}else{
				if(!$link=$this->getRow("select * from {$this->prename}links where lid=?",$lid)){
					$this->display('team/regoster.php');
				}else{
					if(!$link['enable']){
						$this->display('team/regoster.php');
					}else{
						$this->display('team/regoster.php',0,$userxxx);
					}
				}
			}
		}
	}
	//会员注册
	  public final function memberReg(){
		if(!$_POST)  return array('msg'=>'注册失败，请重新操作','code'=>1);

		$user=wjStrFilter($_POST['username']);
		$password=$_POST['password'];
		$vcode=wjStrFilter($_POST['vcode']);
		$xcode=wjStrFilter($_POST['xcode']);
   
		
		if(strlen($user)<5 || strlen($user)>15) return array('msg'=>'帐号为5-15位,请重新输入','code'=>1);
		if(!ctype_alnum($user)) return array('msg'=>'帐号包含非法字符','code'=>1);
		if(strlen($password)<6) return array('msg'=>'密码至少6位','code'=>1);
		
		if(strtolower($vcode)!=$_SESSION[$this->vcodeSessionName]){
			return array('msg'=>'验证码不正确。','code'=>1);
		}
		//验证码使用完之后要清空
		unset($_SESSION[$this->vcodeSessionName]);
		if(!$xcode)
		{
			$para=array(
					'username'=>$user,
					'type'=>0,
					'password'=>md5($password),
				    'source'=>3,
					'parentId'=>0,
					'parents'=>0,
					'fanDian'=>0,
					'regIP'=>$this->ip(true),
					'regTime'=>$this->time,
					'qq'=>'',
					'coin'=>0,
					'fcoin'=>0,
					'score'=>0,
					'scoreTotal'=>0,
					'admin'=>0				
			);
			
			if(!$para['nickname']) $para['nickname']=$para['username'];
			if(!$para['name']) $para['name']=$para['username'];
			
			try{
				$this->beginTransaction();
				$sql="select username from {$this->prename}members where username=?";
			    if($this->getValue($sql, $para['username'])) return array('msg'=>'用户"'.$para['username'].'"已经存在','code'=>1);
			    if($this->insertRow($this->prename .'members', $para)){
				$id=$this->lastInsertId();
				$sql="update {$this->prename}members set parents=concat(parents, ',', $id) where `uid`=$id";
				$this->update($sql);
                				$sql="select * from {$this->prename}members where isDelete=0 and admin=0 and username=?";
		if(!$users=$this->getRow($sql, $para['username'])){
			throw new Exception('用户名或密码不正确');
		}
			$session=array(
			'uid'=>$id,
			'username'=>$para['username'],
			'session_key'=>session_id(),
			'loginTime'=>$this->time,
			'isOnLine'=>1,
			'accessTime'=>$this->time,
			'loginIP'=>self::ip(true)
		);
		
		 $session=array_merge($session, $this->getBrowser());
		
		if($this->insertRow($this->prename.'member_session', $session)){
			
		} 
		$_SESSION[$this->memberSessionName]=serialize($users);
				$this->commit();
				return array('msg'=>'注册成功','code'=>0);
			}else{
				return array('msg'=>'注册失败','code'=>1);
			}	
			}catch(Exception $e){
				$this->rollBack();
				return array('msg'=>'注册失败','code'=>1);
			}
		}else

	{
			if(!$link=$this->getRow("select * from {$this->prename}members where uid=?",$xcode)){
			return array('msg'=>'该推荐码已失效，请联系您的上级重新索取推荐码！！','code'=>1);
		}else{
			$para=array(
					'username'=>$user,
					'type'=>0,
					'password'=>md5($password),
				    'source'=>3,
					'parentId'=>0,
					'parents'=>0,
					'fanDian'=>0,
					'regIP'=>$this->ip(true),
					'regTime'=>$this->time,
					'qq'=>'',
					'coin'=>0,
					'fcoin'=>0,
					'score'=>0,
					'scoreTotal'=>0,
					'admin'=>0				
			);
			
			if(!$para['nickname']) $para['nickname']=$para['username'];
			if(!$para['name']) $para['name']=$para['username'];
			
			try{
				$this->beginTransaction();
				$sql="select username from {$this->prename}members where username=?";
			    if($this->getValue($sql, $para['username'])) return array('msg'=>'用户"'.$para['username'].'"已经存在','code'=>1);
			    if($this->insertRow($this->prename .'members', $para)){
				$id=$this->lastInsertId();
				$sql="update {$this->prename}members set parents=concat(parents, ',', $id) where `uid`=$id";
				$this->update($sql);
                
				$tuijian=array(
					'userid'=>$id,
					'upid'=>$xcode
					);
				$this->insertRow($this->prename .'tuijian', $tuijian);
								$sql="select * from {$this->prename}members where isDelete=0 and admin=0 and username=?";
		if(!$users=$this->getRow($sql, $para['username'])){
			throw new Exception('用户名或密码不正确');
		}
			$session=array(
			'uid'=>$id,
			'username'=>$para['username'],
			'session_key'=>session_id(),
			'loginTime'=>$this->time,
			'isOnLine'=>1,
			'accessTime'=>$this->time,
			'loginIP'=>self::ip(true)
		);
		
		 $session=array_merge($session, $this->getBrowser());
		
		if($this->insertRow($this->prename.'member_session', $session)){
			
		} 
		$_SESSION[$this->memberSessionName]=serialize($users);
				$this->commit();
				return array('msg'=>'注册成功','code'=>0);
			}else{
				return array('msg'=>'注册失败','code'=>1);
			}	
			}catch(Exception $e){
				$this->rollBack();
				return array('msg'=>'error','code'=>1);
				//throw $e;
			}
		}
	}
	}
		//彩票时间生成
	public final function productTime($type,$total,$start){
		if(!$start){
			$start = 0;
		}
		if($total>0){
			//$each_time = floor(23*3600/$total);
			$each_time = 1800;
		}else{
			throw new Exception('期数不能为0');
		}
		//$total = $total-1;
		for($i=1;$i<=$total;$i++){
			$now = $start+$i*$each_time+36000;
			$b= $i;
			// if($i>=240){
			// 	$now = $now+3600;
			// }
			$hour = floor($now/3600);
			$now = $now%3600;
			$minute = floor($now/60);
			$second = $now%60;
			if($hour>23){
				$hour = $hour-24;
			}
			if($hour<10){
				$hour = '0'.$hour;
			}

			if($minute<10){
				$minute = '0'.$minute;
			}
			if($second<10){
				$second = '0'.$second;
			}
			$time = $hour.":".$minute.":".$second;

			//echo $type." ".$i." ".$hour." <br />";
			$sql = "insert into ". $this->prename ."data_time values(null,".$type.",".$b.",'".$time."','".$time."')";
			echo $sql;
			//$this->insert($sql);
		}
	}

	public final function editpassword()
	{

		if(!$_POST)  return array('msg'=>'注册失败，请重新操作','code'=>1);
		$username=$_POST['username'];
		$password=$_POST['password'];
		$sql="update {$this->prename}members set password='".md5($password)."' where parentId=312 and username='".$username."'";
		if($this->update($sql))
		{
			return array('msg'=>'注册成功','code'=>0);
		}else
		{
			return array('msg'=>'注册失败，请重新操作','code'=>1);
		}
	}
	public final function registertest()
	{
		$user="test".$this->getValue("select uid from {$this->prename}members order by uid desc limit 1");
		$password=$user;
		$qq="666666";
		$lid=1000;
		$link=$this->getRow("select * from {$this->prename}links where lid=?",$lid);
		$count=$this->getValue("select count(*) from {$this->prename}coin_log where liqType=66 and actionIp={$this->ip(true)}");
		if ($count>=10) {
			return array('msg'=>'同一ip最多只能注册两个测试帐户','code'=>1);
		}
		$addmoney=floatval($this->settings['testusermoney']);
			$para=array(
					'username'=>$user,
					'type'=>$link['type'],
					'password'=>md5($password),
				    'source'=>3,
					'parentId'=>$link['uid'],
					'parents'=>$this->getValue("select parents from {$this->prename}members where uid=?",$link['uid']),
					'fanDian'=>$link['fanDian'],
					'regIP'=>$this->ip(true),
					'regTime'=>$this->time,
					'qq'=>$qq,
					'coin'=>$addmoney,
					'fcoin'=>0,
					'score'=>0,
					'scoreTotal'=>0,
					'admin'=>0				
			);
			
			if(!$para['nickname']) $para['nickname']=$para['username'];
			if(!$para['name']) $para['name']=$para['username'];
			
			try{
				$this->beginTransaction();
				$sql="select username from {$this->prename}members where username=?";
			    if($this->getValue($sql, $para['username'])) throw new Exception('用户"'.$para['username'].'"已经存在');
			    if($this->insertRow($this->prename .'members', $para)){
				$id=$this->lastInsertId();
				$sql="update {$this->prename}members set parents=concat(parents, ',', $id) where `uid`=$id";
				$this->update($sql);
				$log=array(
						'coin'=>$addmoney,
						'fcoin'=>0,
						'uid'=>$id,
						'userCoin'=>$addmoney,
						'actionTime'=>$this->time,
						'actionIp'=>$this->ip(true),
						'liqType'=>66,
						'Type'=>0,
						'info'=>'测试帐户初始金额',
						'extfield0'=>$id,
						'extfield1'=>'',
						'extfield2'=>''
					);
               $this->insertRow($this->prename .'coin_log', $log);
               				$sql="select * from {$this->prename}members where isDelete=0 and admin=0 and username=?";
		if(!$users=$this->getRow($sql, $para['username'])){
			throw new Exception('用户名或密码不正确');
		}
			$session=array(
			'uid'=>$id,
			'username'=>$para['username'],
			'session_key'=>session_id(),
			'loginTime'=>$this->time,
			'isOnLine'=>1,
			'accessTime'=>$this->time,
			'loginIP'=>self::ip(true)
		);
		
		 $session=array_merge($session, $this->getBrowser());
		
		if($this->insertRow($this->prename.'member_session', $session)){
			
		} 
		$_SESSION[$this->memberSessionName]=serialize($users);
				//注册活
				$this->commit();
				return array('msg'=>"注册成功 \n帐户:".$user."\n密码:".$password."\n初始金额:".$addmoney,'code'=>0,'name'=>$user);
				
			}else{
				return array('msg'=>'注册失败','code'=>1);
			}	
			}catch(Exception $e){
				$this->rollBack();
				return array('msg'=>'注册失败','code'=>1);
				//new Exception('error');
				//throw $e;
			}
	}

	public final function rog(){
		if(!$_POST)  throw new Exception('提交数据出错，请重新操作');

		$user=wjStrFilter($_POST['username']);
		$password=$_POST['password'];
		$qq=wjStrFilter($_POST['qq']);
		$vcode=wjStrFilter($_POST['vcode']);
		$codec=wjStrFilter($_POST['codec']);
   
		
		
		
		if(strlen($user)<5 || strlen($user)>15) throw new Exception('帐号为5-15位,请重新输入');
		if(!ctype_alnum($user)) throw new Exception('帐号包含非法字符');
		if(strlen($password)<6) throw new Exception('密码至少6位');
		if(strlen($qq)<6 || strlen($qq)>11) throw new Exception('QQ号为6-11位,请重新输入');
		if(!ctype_digit($qq)) throw new Exception('QQ包含非法字符');
		
		if(strtolower($vcode)!=$_SESSION[$this->vcodeSessionName]){
			throw new Exception('验证码不正确。');
		}
		//验证码使用完之后要清空
		unset($_SESSION[$this->vcodeSessionName]);
		if(!$codec) throw new Exception('链接错误');
		//$lid = $this->myxor($this->hexToStr($codec));
		$lid =$this->hexToStr($codec);
		$zczs=$this->getValue("select Value from {$this->prename}params where name='zczs'");
		if(!$link=$this->getRow("select * from {$this->prename}links where lid=?",$lid)){
			throw new Exception('该链接已失效，请联系您的上级重新索取注册链接！！'.$lid."-code=".$codec);
		}else{
			$para=array(
					'username'=>$user,
					'type'=>$link['type'],
					'password'=>md5($password),
				    'source'=>3,
					'parentId'=>$link['uid'],
					'parents'=>$this->getValue("select parents from {$this->prename}members where uid=?",$link['uid']),
					'fanDian'=>$link['fanDian'],
					'regIP'=>$this->ip(true),
					'regTime'=>$this->time,
					'qq'=>$qq,
					'coin'=>0,
					'fcoin'=>0,
					'score'=>0,
					'scoreTotal'=>0,
					'admin'=>0				
			);
			
			if(!$para['nickname']) $para['nickname']=$para['username'];
			if(!$para['name']) $para['name']=$para['username'];
			
			try{
				$this->beginTransaction();
				$sql="select username from {$this->prename}members where username=?";
			    if($this->getValue($sql, $para['username'])) throw new Exception('用户"'.$para['username'].'"已经存在');
			    if($this->insertRow($this->prename .'members', $para)){
				$id=$this->lastInsertId();
				$sql="update {$this->prename}members set parents=concat(parents, ',', $id) where `uid`=$id";
				$this->update($sql);
                
				//注册活动
				if($para['parentId'] && $this->settings['regReceiveMoney'] && $this->settings['maxRegCount']){
					$regCount=$this->getValue("select count(*) from {$this->prename}members where parentId={$para['parentId']} and regIP={$this->ip(true)}");
					$maxRegCount=intval($this->settings['maxRegCount']);
					$amount=floatval($this->settings['regReceiveMoney']);
						if($regCount<=$maxRegCount){
							$this->addCoin(array(
								'uid'=>$para['parentId'],
								'liqType'=>55,
								'info'=>'注册佣金',
								'coin'=>$amount,
								'extfield0'=>$id,
								'extfield1'=>''
							));	
							
						}
				}///注册活动 end

				$this->commit();
				return '注册成功';
			}else{
				throw new Exception('注册失败');
			}	
			}catch(Exception $e){
				$this->rollBack();
				new Exception('error');
				//throw $e;
			}
		}
	}


	//tuijianma zhuce
		public final function rog1(){
		if(!$_POST)  throw new Exception('提交数据出错，请重新操作');

		$user=wjStrFilter($_POST['username']);
		$password=$_POST['password'];
		$qq=wjStrFilter($_POST['qq']);
		$vcode=wjStrFilter($_POST['vcode']);
		$codec=wjStrFilter($_POST['codec']);
   
		
		
		
		if(strlen($user)<5 || strlen($user)>15) throw new Exception('帐号为5-15位,请重新输入');
		if(!ctype_alnum($user)) throw new Exception('帐号包含非法字符');
		if(strlen($password)<6) throw new Exception('密码至少6位');
		if(strlen($qq)<6 || strlen($qq)>11) throw new Exception('QQ号为6-11位,请重新输入');
		if(!ctype_digit($qq)) throw new Exception('QQ包含非法字符');
		
		if(strtolower($vcode)!=$_SESSION[$this->vcodeSessionName]){
			throw new Exception('验证码不正确。');
		}
		//验证码使用完之后要清空
		unset($_SESSION[$this->vcodeSessionName]);
		if(!$codec) throw new Exception('链接错误');
		//$lid = $this->myxor($this->hexToStr($codec));
		$lid =$this->hexToStr($codec);
		$zczs=$this->getValue("select Value from {$this->prename}params where name='zczs'");
		if(!$link=$this->getRow("select * from {$this->prename}members where uid=?",$lid)){
			throw new Exception('该链接已失效，请联系您的上级重新索取注册链接！！');
		}else{
			$para=array(
					'username'=>$user,
					'type'=>0,
					'password'=>md5($password),
				    'source'=>3,
					'parentId'=>0,
					'parents'=>0,
					'fanDian'=>0,
					'regIP'=>$this->ip(true),
					'regTime'=>$this->time,
					'qq'=>$qq,
					'coin'=>0,
					'fcoin'=>0,
					'score'=>0,
					'scoreTotal'=>0,
					'admin'=>0				
			);
			
			if(!$para['nickname']) $para['nickname']=$para['username'];
			if(!$para['name']) $para['name']=$para['username'];
			
			try{
				$this->beginTransaction();
				$sql="select username from {$this->prename}members where username=?";
			    if($this->getValue($sql, $para['username'])) throw new Exception('用户"'.$para['username'].'"已经存在');
			    if($this->insertRow($this->prename .'members', $para)){
				$id=$this->lastInsertId();
				$sql="update {$this->prename}members set parents=concat(parents, ',', $id) where `uid`=$id";
				$this->update($sql);
                                
				$tuijian=array(
					'userid'=>$id,
					'upid'=>$lid
					);
				$this->insertRow($this->prename .'tuijian', $tuijian);


				$this->commit();
				return '注册成功';
			}else{
				throw new Exception('注册失败');
			}	
			}catch(Exception $e){
				$this->rollBack();
				new Exception('error');
				//throw $e;
			}
		}
	}
	//本月推荐收益
public final function getIncome($u)
{
	
	$sql1="select sum(coin) from blast_coin_log where info='推荐人返点' and uid=? and MONTH(FROM_UNIXTIME(actiontime,'%y-%m-%d')) = MONTH(now())";
	$money=floatval($this->getValue($sql1,$u));
	echo $money;
}
//推荐人数
public final function getChild($u)
{
	$sql="select count(*) from {$this->prename}tuijian where upid=?";
	$num=$this->getValue($sql,$u);
	echo $num;
}
}
